package com.cn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.entity.Goods;
import com.cn.mapper.GoodsMapper;
import com.cn.mapper.OrderInfoMapper;
import com.cn.service.GoodsService;
import com.cn.utlis.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author: chenyuncong
 * @Date: 2020/6/28 10:34
 */
@Service("goodsService")
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {
    @Autowired
    private RedisTemplate redisTemplate;

    @Resource
    private OrderInfoMapper orderInfoMapper;

    @Override
    @Transactional
    public void startGoodsBuy(Long id){
        //获取到商品信息
        Goods  goods = this.getById(id);
        //检查一下订单量
//        orderInfoMapper.
        //商品库存
        Integer goodsStock = goods.getGoodsStock();
        //设置了
        redisTemplate.opsForValue().increment(Constants.REDIS_GOODS_SIGN+goods.getId(),goodsStock.longValue());
    }
}
